package cn.net.gemai.springboot_eureka_client_customer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.swing.*;

@RestController
public class CallProviderController {

    @Resource
    private RestTemplate restTemplate;

    @ResponseBody
    @RequestMapping("/getProviderContent")
    public String buyTicket(String name){

        /**
         * 使用负载均衡时，域名直接使用注册到Eureka中的服务名称，即provider服务的spring.application.name
         */
        String providerName = "service-provider";
        String url = "http://" + providerName + "/getContent";
        String template = restTemplate.getForEntity(url,String.class).getBody();
        return name+"购买了"+template;
    }
}
